package net.lzzy.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpSession;
import java.util.Calendar;

@Controller
public class LoginController {
    @GetMapping("/toLoginPage")
    public String toLoginPage(Model model){
        model.addAttribute("currentYear", Calendar.getInstance().get(Calendar.YEAR));
        return "login";
    }

    @PostMapping("/login")
    public String loginIn(@RequestParam("username") String username,
                          @RequestParam("password") String password, HttpSession session){
        if(username.equals("xxx") && password.equals("123")){
            session.setAttribute("username","xxx");
            return "redirect:/admin/article";
        }
        else
            return "login";
    }

}
